﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Collections;
using System.Data;
using CE.Database;
/// <summary>
/// Summary description for CarParallelImportDB
/// </summary>
/// 
namespace CE.Provider
{
    public class CarParallelImportDB
    {
        public CarParallelImportDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public Int64 Insert(CarParallelImport carparallelimport)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "[sprocProviderCarParallellImportInsertUpdateSingleItem]";

            SortedList _sPara = new SortedList();
            _sPara.Add("@ProviderCarParallellImportId", carparallelimport.ProviderCarParallelImportId);
            _sPara.Add("@ProviderCompanyId", carparallelimport.ProviderCompanyId);
            _sPara.Add("@IsParallelImport", carparallelimport.IsParallelImport);
            _sPara.Add("@ParallelImportValue", carparallelimport.ParallelImportValue);
            _sPara.Add("@RefCEUserId", carparallelimport.RefCEUserId);
            _sPara.Add("@Status", carparallelimport.Status);
            #region Parameter
            //_sPara.Add("@Info1", carturboengine.Info1);
            //_sPara.Add("@Info2", carturboengine.Info2);
            //_sPara.Add("@Info3", carturboengine.Info3);
            //_sPara.Add("@Info4", carturboengine.Info4);
            //_sPara.Add("@Info5", carturboengine.Info5);
            //_sPara.Add("@NInfo1", carturboengine.NInfo1);
            //_sPara.Add("@NInfo2", carturboengine.NInfo2);
            //_sPara.Add("@FInfo1", carturboengine.FInfo1);
            //_sPara.Add("@FInfo2", carturboengine.FInfo2);
            //_sPara.Add("@DInfo1", carturboengine.DInfo1);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public DataTable GetCarParallelImportList(Int64 ProviderCarParallelImportId, Int64 RefCEUserId)
        {
            DataTable _cclist = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderCarParallelImportSelectItemList";

            SortedList _spara = new SortedList();
            _spara.Add("@RefCEUserId", RefCEUserId);
            _spara.Add("@ProviderCarParallelImportId", ProviderCarParallelImportId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _cclist = _dt;
                }
            }
            return _cclist;
        }

        public DataTable GetCarParallelImportList(Int64 RefCEUserId)
        {
            DataTable _cpilist = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderCarParallelImportSelectItemList";

            SortedList _spara = new SortedList();
            _spara.Add("@RefCEUserId", RefCEUserId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _cpilist = _dt;
                }
            }
            return _cpilist;
        }

        public CarParallelImport GetCarParallelImport(Int64 ProviderCompanyId, bool IsParallelImport)
        {
            CarParallelImport _carparallelimport = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderCarParallelImportSelectSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);
            _spara.Add("@IsParallelImport", IsParallelImport);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _carparallelimport = new CarParallelImport();
                    _carparallelimport = FillDataRecord(_dt, 0);
                }
            }
            return _carparallelimport;
        }

        private CarParallelImport FillDataRecord(DataTable myDataTable, int RowId)
        {
            CarParallelImport myCarParallelImport = new CarParallelImport();
            myCarParallelImport.ProviderCarParallelImportId = Convert.ToInt64(myDataTable.Rows[RowId]["ProviderCarParallellImportId"].ToString());
            myCarParallelImport.ProviderCompanyId = Convert.ToInt64(myDataTable.Rows[RowId]["ProviderCompanyId"].ToString());
            myCarParallelImport.IsParallelImport = Convert.ToBoolean(myDataTable.Rows[RowId]["IsParallelImport"].ToString());
            myCarParallelImport.ParallelImportValue = Convert.ToSingle(myDataTable.Rows[RowId]["ParallelImportValue"].ToString());
            myCarParallelImport.RefCEUserId = Convert.ToInt64(myDataTable.Rows[RowId]["RefCEUserId"].ToString());
            myCarParallelImport.Status = Convert.ToBoolean(myDataTable.Rows[RowId]["Status"].ToString());
            myCarParallelImport.CreatedDate = Convert.ToDateTime(myDataTable.Rows[RowId]["CreatedDate"].ToString());
            myCarParallelImport.ModifiedDate = Convert.ToDateTime(myDataTable.Rows[RowId]["ModifiedDate"].ToString());
            return myCarParallelImport;
        }

    }
}